home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Utils / AutoComment / AutoComment.C < prev    next >
C/C++ Source or Header  |  1996-06-25  |  5KB  |  197 lines

  1. /*** Include Files ***/
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <dos/dos.h>
  6. #include <dos/notify.h>
  7. #include <dos/dostags.h>
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <ctype.h>
  13. #include <dos.h>
  14.  
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17.  
  18. /*** Some Variables ***/
  19.  
  20. #define MAX_FILES 200
  21. char filenames[2][MAX_FILES][33];
  22. int  amountfiles[2]={0,0};
  23. BOOL quiet=FALSE;
  24.  
  25. char dirname[101]="HBBS:Nodes/Node0/PlayPen";
  26. static UBYTE   *VersTag = "\0$VER: AutoComment 1.0 (22.06.96)";
  27. extern struct Library *DOSBase;
  28.  
  29. /*** start program ***/
  30.  
  31. void CommentTheFile(char *filename)
  32. {
  33.   char *name;
  34.   int namelen;
  35.  
  36.   namelen=strlen(filename)+strlen(dirname)+2;
  37.   name=malloc(namelen);
  38.   strcpy(name,dirname);
  39.   AddPart(name,filename,namelen);
  40.   if (!quiet) printf("namelen %d, name %s\n",namelen,name);
  41.   SetComment(name,"This file came from Utopia!");
  42. }
  43.  
  44. void GetFileList(int buffer)
  45. {
  46.   BPTR FL;
  47.   struct FileInfoBlock *FB;
  48.   long err;
  49.   char tmpstr[401];
  50.   BPTR fp;
  51.  
  52.   amountfiles[buffer]=0;
  53.   if (FB=AllocMem(sizeof(struct FileInfoBlock),0L))
  54.   {
  55.     if ((FL=Lock(dirname,(long)ACCESS_READ))==NULL)
  56.     {
  57.       if (!quiet) printf("Error Locking Dir!");
  58.     }
  59.     else
  60.     {
  61.       err= !Examine(FL,FB);
  62.       if (!err)
  63.       {
  64.         do
  65.         {
  66.           err=!ExNext(FL,FB);
  67.           if (!err)
  68.           {
  69.             if (FB->fib_DirEntryType<0 && FB->fib_Size>0 && amountfiles[buffer]<MAX_FILES)
  70.             {
  71.               strcpy(tmpstr,dirname);
  72.               AddPart(tmpstr,FB->fib_FileName,400);
  73.               if ((fp=Open(tmpstr,MODE_OLDFILE))!=NULL)
  74.               {
  75.                 Close(fp);
  76.                 strcpy(filenames[buffer][amountfiles[buffer]],FB->fib_FileName);
  77.                 amountfiles[buffer]++;
  78.               }
  79.             }
  80.           }
  81.         } while (!err);
  82.       }
  83.       UnLock(FL);
  84.     }
  85.     FreeMem(FB,sizeof(struct FileInfoBlock));
  86.   }
  87.   else if (!quiet) printf("Memory allocation error!!");
  88.  
  89. }
  90.  
  91. void CheckNewFiles(void)
  92. {
  93.   int loop1,loop2;
  94.   BOOL found=FALSE;
  95.  
  96.   for (loop1=0;loop1<amountfiles[0];loop1++)
  97.   {
  98.     loop2=0;
  99.     found=FALSE;
  100.     do
  101.     {
  102.       /*if (!quiet) printf("Comparing %d to %d\n",loop1,loop2);*/
  103.       if (stricmp(filenames[0][loop1],filenames[1][loop2])==0)
  104.       {
  105.         found=TRUE;
  106.       }
  107.       loop2++;
  108.     } while (loop2<amountfiles[1] && !found);
  109.     if (!found)
  110.     {
  111.       CommentTheFile(filenames[0][loop1]);
  112.     }
  113.   }
  114. }
  115.  
  116. void CopyFileList(int from, int to)
  117. {
  118.   int loop;
  119.  
  120.   for (loop=0;loop<amountfiles[from];loop++)
  121.   {
  122.     strcpy(filenames[to][loop],filenames[from][loop]);
  123.   }
  124.   amountfiles[to]=amountfiles[from];
  125. }
  126.  
  127. void main(int argc, char **argv)
  128. {
  129.  
  130.   BOOL done=FALSE;
  131.   struct NotifyRequest *notifyrequest;
  132.   UBYTE *filename;
  133.   LONG signum;
  134.   ULONG signals;
  135.  
  136.   int loop;
  137.  
  138.   for (loop=1;loop<argc;loop++)
  139.   {
  140.     printf("%d %s",loop,argv[loop]);
  141.     if (stricmp("QUIET",argv[loop])) quiet=TRUE;
  142.   }
  143.  
  144.   if (!quiet) printf("\23332m\2331m--> AutoComment! <--\2330m V1.0 (C) 1994 Hydra of Perspex/LSD/RDC!\n");
  145.  
  146.   if (DOSBase->lib_Version >= 37)
  147.   {
  148.     /* Allocate a NotifyRequest structure */
  149.     if (notifyrequest = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR))
  150.     {
  151.       /* And allocate a signalsbit */
  152.       if ((signum = AllocSignal(-1L)) != -1)
  153.       {
  154.         /* Initialize notification request */
  155.         filename = dirname;
  156.         notifyrequest->nr_Name = filename;
  157.         notifyrequest->nr_Flags = NRF_SEND_SIGNAL;
  158.         /* Signal this task */
  159.         notifyrequest->nr_stuff.nr_Signal.nr_Task = (struct Task *) FindTask(NULL);
  160.         /* with this signal bit */
  161.         notifyrequest->nr_stuff.nr_Signal.nr_SignalNum = signum;
  162.  
  163.         if ((StartNotify(notifyrequest)) == DOSTRUE)
  164.         {
  165.           if (!quiet) printf("Press \23334mCTRL-C\23331m in this window to exit AutoComment\n\n");
  166.  
  167.           GetFileList(1);  // Get the list of all files in the directory.
  168.  
  169.           while(!done)
  170.           {
  171.             if (!quiet) printf("\23332;43mWaiting..\23331;40m\n");
  172.  
  173.             signals = Wait(  (1L << signum) | SIGBREAKF_CTRL_C  );
  174.             if (signals & (1L << signum))
  175.             {
  176.               GetFileList(0);
  177.               CheckNewFiles();
  178.               CopyFileList(0,1);
  179.             }
  180.             if (signals & SIGBREAKF_CTRL_C)
  181.             {
  182.               done=TRUE;
  183.             }
  184.           }
  185.         }
  186.         else if (!quiet) printf("AutoComment Can't start notification\n");
  187.         FreeSignal(signum);
  188.       }
  189.       else if (!quiet) printf("No signals available\n");
  190.       FreeMem(notifyrequest, sizeof(struct NotifyRequest));
  191.     }
  192.     else if (!quiet) printf("No Mem available\n");
  193.   }
  194.   else if (!quiet) printf("AutoID Requires at least V37 dos.library\n");
  195.   if (!quiet) printf("Thanks for using AutoComent From Perspex, Written By HYDRA!");
  196. }
  197.